from selenium import webdriver
import time
from unittest import TestCase


# 登录
def dengLu():
    username = "hanyan"
    password = "123456"
    expect = "Student Login"
    driver.find_element_by_xpath("//*[@id='loginname']").send_keys(username)
    time.sleep(1)
    driver.find_element_by_xpath("//*[@id='password']").send_keys(password)
    time.sleep(1)
    driver.find_element_by_xpath("//*[@id='submit']").click()
    time.sleep(1)
    res = driver.title
    if expect != res:
        driver.save_screenshot("登陆失败.jpg")


def shangChuang():
    # 上传图片
    driver.find_element_by_xpath(r'//*[@id="img"]').click()
    time.sleep(2)
    driver.find_element_by_xpath(r'//*[@id="file1"]').send_keys(r"C:\Users\92520\Pictures\Saved Pictures\002.jpg")
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="pic_btn"]').click()
    time.sleep(1)


def XiuGai_TX():
    # 修改头像
    driver.find_element_by_xpath(r'//*[@id="ul_pic"]/li[4]/img').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="tt"]/div[1]/div[3]/ul/li[1]/a').click()
    time.sleep(2)


def TiJiao():
    # 提交今日评价
    driver.find_element_by_xpath(r'//*[@id="form_table"]/tbody/tr[9]/td[2]/div/label[2]/div').click()
    driver.find_element_by_xpath(r'//*[@id="textarea"]').send_keys("完全欧克")
    time.sleep(2)


def XG_xinxi():
    # 修改个人信息
    driver.find_element_by_xpath(r'//*[@id="_easyui_tree_8"]').click()
    time.sleep(2)
    driver.find_element_by_xpath(r'//*[@id="info"]/table/tbody/tr[9]/td[2]/textarea').send_keys("相遇如樱花落")
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="btn_modify"]').click()
    time.sleep(2)


def CX_haoyou():
    # 查询所有好友
    driver.find_element_by_xpath(r'//*[@id="_easyui_tree_10"]').click()
    time.sleep(1)


def TuiChu():
    # 退出
    driver.find_element_by_xpath(r'//*[@id="top"]/div/a[2]').click()


# # 登录教师模块
def teacher():
    driver.find_element_by_xpath(r'/html/body/div/div/div[1]/div[2]/a[2]').click()
    time.sleep(1)
    name = "jason"
    password1 = "admin"
    driver.find_element_by_xpath(r'//*[@id="loginname"]').send_keys(name)
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="password"]').send_keys(password1)
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="submit"]').click()
    time.sleep(1)


def Teacher_inquire():
    # 教师管理:查询，重置密码
    driver.find_element_by_xpath(r'//*[@id="_easyui_tree_11"]/span[4]/a').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="sear_teaname"]').send_keys("贾生")
    time.sleep(2)
    driver.find_element_by_xpath(r'//*[@id="search_user"]/span').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="datagrid-row-r1-2-0"]/td[9]/div/a').click()
    time.sleep(1)
    driver.switch_to.alert.accept()


def Teacher_student():
    # 学生模块
    driver.find_element_by_xpath(r'//*[@id="_easyui_tree_12"]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="J-stu"]').send_keys("jason")
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="J-phone"]').send_keys("13548554150")
    time.sleep(2)
    driver.find_element_by_xpath(r'//*[@id="stu_panel"]/div/div/div[1]/table/tbody/tr/td[4]/a').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="datagrid-row-r2-2-0"]/td[11]/div/a').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'/html/body/div[9]/div[3]/a').click()
    time.sleep(1)


def Teacher_course():
    # 课程管理
    driver.find_element_by_xpath(r'//*[@id="_easyui_tree_13"]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="course_panel"]/div/div/div[1]/table/tbody/tr/td/a').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="course_form_add"]/table/tbody/tr[1]/td[2]/input').send_keys("美羊羊6号")
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="course_form_add"]/table/tbody/tr[2]/td[2]/textarea').send_keys("美羊羊为何如此双标")
    time.sleep(1)
    driver.find_element_by_xpath(r'/html/body/div[9]/div[3]/a[1]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'/html/body/div[12]/div[3]/a').click()


def Teacher_evaluate():
    # 今日评价
    driver.find_element_by_xpath(r'//*[@id="_easyui_tree_15"]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="eva"]/div/div/div[1]/table/tbody/tr/td[2]/a').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'/html/body/div[12]/div[3]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="eva"]/div/div/div[1]/table/tbody/tr/td[4]/a').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'/html/body/div[12]/div[3]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="_easyui_tree_16"]').click()


def Teacher_journal():
    # 日志
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="_easyui_tree_18"]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="history"]/div/div/div[1]/table/tbody/tr/td[1]/a/span/span').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="laydate_YY"]/a[1]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="laydate_YY"]/a[1]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="laydate_MM"]/a[2]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="laydate_MM"]/a[2]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="laydate_MM"]/a[2]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="laydate_table"]/tbody/tr[5]/td[5]').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="history"]/div/div/div[1]/table/tbody/tr/td[2]/a/span').click()
    time.sleep(1)
    driver.find_element_by_xpath(r'//*[@id="history"]/div/div/div[1]/table/tbody/tr/td[4]/a').click()


driver = webdriver.Chrome()

driver.get("http://localhost:8080/HKR")
driver.maximize_window()

dengLu()
shangChuang()
XiuGai_TX()
TiJiao()
XG_xinxi()
CX_haoyou()
TuiChu()
teacher()
Teacher_inquire()
Teacher_student()
Teacher_course()
Teacher_evaluate()
Teacher_journal()
